import 'package:flutter/material.dart';
import 'package:flutter_baselib/lib.dart';

///@date:  2021/3/3 15:35
///@author:  lixu
///@description: http请求默认显示的弹窗
class HttpLoadingDialog extends Dialog {
  ///加载提示
  final String loadingText;

  ///是否能通过物理按钮关闭弹窗
  ///关闭时，取消请求
  final bool isCanCloseDialog;

  ///手动关闭弹窗时，取消http请求
  final CancelToken cancelToken;

  HttpLoadingDialog(this.loadingText, this.isCanCloseDialog, this.cancelToken);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        if (isCanCloseDialog) {
          cancelToken?.cancel();
        }
        return isCanCloseDialog;
      },
      child: Center(
        child: Material(
          color: Colors.transparent,
          child: Center(
            child: SizedBox(
              width: 120.0,
              height: 120.0,
              child: Container(
                decoration: ShapeDecoration(
                  color: Color(0x99000000),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8.0),
                    ),
                  ),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    CircularProgressIndicator(
                      valueColor: AlwaysStoppedAnimation(
                        Colors.white,
                      ),
                      strokeWidth: 2.0,
                    ),
                    Padding(
                      padding: const EdgeInsets.only(
                        top: 20.0,
                      ),
                      child: Text(
                        loadingText,
                        style: TextStyle(fontSize: 15.0, color: Colors.white),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
